/**
 * 
 */
package cwinsor.com.leaf_raking;

import java.io.File;
import java.io.IOException;

import com.infomata.data.CSVFormat;
import com.infomata.data.DataFile;
import com.infomata.data.DataRow;
import com.infomata.data.TabFormat;

/**
 * @author cwinsor
 *
 */
public class RakingAssignmentMachine extends Thread {



	/* Make the assignments (raker to customer)
	 */
	public void run() {
		System.out.printf(this.getClass().getPackage().getName() + "running...\n"); 
		

		String userHomeDir = System.getProperty("user.home", ".");
		String userFilesDir = userHomeDir + "\\Documents\\me\\_BHRA_2013\\leaf raking\\schedule_files";
		
		System.out.printf("userHomeDir=" + userHomeDir + " userFilesDir=" + userFilesDir + "\n"); 
		
		
		// Creating a reader for CSV file using ISO-8859-1
		 
		 DataFile read = DataFile.createReader("8859_1");
		 read.setDataFormat(new CSVFormat());
		 
		 try
		 {
		 
		     read.open(new File(userFilesDir + "\\test.csv"));
		 
		     for (DataRow row = read.next(); row != null; row = read.next())
		     {
		         String text = row.getString(0);
		         int number1 = row.getInt(1, 0);
		         double number2 = row.getDouble(2);
		         // use the retrieved data ...
		     }
		 } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 finally
		 {
		     read.close();
		 }
		 
		 // Creating a writer for data file with European encoding
		 // ISO-8859-2 (European) using tab separated format.
		 // (rewrite existing file)
		 
		 DataFile write = DataFile.createWriter("8859_2", false);
		 write.setDataFormat(new CSVFormat());
		 
		 try
		 {
		 
		     write.open(new File(userFilesDir + "\\test_out.csv"));
		 
		     
		     for (int x=0; x<10; x++)
		     {
		    	 DataRow row = write.next();
		    	 row.add("some German text");
		         row.add(123);
		         row.add(456);
		         row.add(13323.23d);
		     }
		 } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 finally
		 {
		     write.close();
		 }
		 
		
		
		System.out.printf(this.getClass().getPackage().getName() + "done...\n"); 
//		boolean done = false;
//		while (!done) {
//			try {
//				Thread.currentThread();
//				Thread.sleep(1);
//			} catch (InterruptedException e) {
//				done = true;
//			}
//		}
	}

}
